package com.itheima.health.config;
import com.itheima.health.entity.AliOssProperties;
import com.itheima.health.utils.AliOssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类，用于创建AliOssUtil对象
 */
@Configuration
public class OssConfiguration {

    @Bean//注册bean对象 由方法得返回值提供
    @ConditionalOnMissingBean//如果容器没有bean对象则注册一个，如果已经存在就不注册
    public AliOssUtil aliOssUtil(@Autowired AliOssProperties aliOssProperties){
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}